/**
 * 
 */
define([],function(QueryDefTpl){
	webUtils.nameSpace("FormBuilder");
	
	FormBuilder.columnViewModel=function(param){
		FormBuilder.columnViewModel.map={
				1:FormBuilder.columnViewModel.type1,//一列式
				11:FormBuilder.columnViewModel.type11,//两列式,默认
				111:FormBuilder.columnViewModel.type111//三列式
		}
		
		var me=this;
		var columnViewModel=FormBuilder.columnViewModel.map[param.type];
		if(columnViewModel){
			return new columnViewModel(param);
		}else{
			return null;
		}
	}
	
	FormBuilder.columnViewModel.type1=function(param){
		var me=this;
		var cutNum=1;//默认以两列为单位
		var currentColInRow=1;//当前列在当前行的位置，1表示本行的第一列 
		var currentRowObj=null;
		me.append=function(ctr){
			var currentCtr=ctr.getViewObj();
			
			currentRowObj=$('<div class="row"></div>');//添加一行
			param.formViewDom.append(currentRowObj);
			
			currentCol=$('<div class="col-md-12"></div>');//只有一行
			
			currentRowObj.append(currentCol);
			currentCol.append(currentCtr);
			ctr.afterAppend();
			
			currentColInRow++;
		}
	}
	
	FormBuilder.columnViewModel.type11=function(param){
		var me=this;
		var cutNum=2;//默认以两列为单位
		var currentColInRow=1;//当前列在当前行的位置，1表示本行的第一列 
		var currentRowObj=null;
		me.append=function(ctr){
			var currentCtr=ctr.getViewObj();
			if(ctr.getRequiredSapce()==Control.spaceClass.s || ctr.getRequiredSapce()==Control.spaceClass.d){
				if(currentColInRow==1){//重新增加一行
					currentRowObj=$('<div class="row"></div>');
					param.formViewDom.append(currentRowObj);
				}
				currentCol=$('<div class="col-md-6"></div>');
			}else{
				//自动占用多行
				currentRowObj=$('<div class="row"></div>');
				param.formViewDom.append(currentRowObj);
				
				currentCol=$('<div class="col-md-12"></div>');
				currentColInRow=cutNum;
			}
			
			currentRowObj.append(currentCol);
			currentCol.append(currentCtr);
			ctr.afterAppend();
			
			if(currentColInRow==cutNum){
				currentColInRow=1;
			}else{
				currentColInRow++;
			}
		}
	};
	
	FormBuilder.columnViewModel.type111=function(param){
		var me=this;
		var cutNum=3;//总空间
		var currentResidualSpace=3;//当前剩余空间
		var currentRowObj=null;
		me.append=function(ctr){
			var currentCtr=ctr.getViewObj();
			//计算需要空间
			var eedSpace=0; 
			if(ctr.getRequiredSapce()==Control.spaceClass.s || ctr.getRequiredSapce()==Control.spaceClass.d){
				needSpace=1;
			}else if(ctr.getRequiredSapce()==Control.spaceClass.m){
				needSpace=2;
			}else if(ctr.getRequiredSapce()==Control.spaceClass.l){
				needSpace=3;
			}
			//计算空间是否满足
			if(currentResidualSpace<=0 || currentResidualSpace<needSpace){
				currentResidualSpace=3;
				currentRowObj=$('<div class="row"></div>');
				param.formViewDom.append(currentRowObj);
			}
			
			if(needSpace==1){
				currentCol=$('<div class="col-md-6"></div>');
			}else if(needSpace==2){
				currentCol=$('<div class="col-md-8"></div>');
			}else if(needSpace==3){
				currentCol=$('<div class="col-md-12"></div>');s
			}
			
			currentResidualSpace=currentResidualSpace-needSpace;
			currentRowObj.append(currentCol);
			currentCol.append(currentCtr);
			ctr.afterAppend();
			
		}
	};
	
	return FormBuilder.columnViewModel;
});